package com.example.md.mddemo.controller;

import com.example.md.mddemo.exception.RestResVo;
import com.example.md.mddemo.exception.UserException;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Copyright © 2018年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * 统一处理一组异常例子,指定处理@RestController注解
 * @Date 2018/9/14 16:00
 */
@RestControllerAdvice(annotations = RestController.class)
@Order(-9527)//越小优先级越高
public class UserRestControllerAdvice {

    /**
     * ControllerAdvice中的ExceptionHandler会对ControllerAdvice作用域中的Controller生效
     * @param e
     * @return
     */
    @ExceptionHandler
    public RestResVo<Void> handleUserException(UserException e){
        return RestResVo.error(e);
    }

}
